import { Document, OptionalId } from "mongodb";
import { mongo } from "../mogoConfig";

interface CustomDoc extends Document {
    "_id": Number,
    color: String
}

const run = async () => {
    const pizzaMenuTB = mongo.db("my_test").collection("pizzaMenu")

    await pizzaMenuTB.deleteMany()

    const result1 = await pizzaMenuTB.insertOne(
        { name: "Neapolitan pizza", shape: "round" }
    )
    console.log("执行结果1------------------")
    console.log(JSON.stringify(result1))




    const docs = [{ "_id": 1, "color": "red" },
    { "_id": 2, "color": "purple" },
    { "_id": 3, "color": "blue" }]
    const pizzaMenuTB2 = mongo.db("my_test").collection<CustomDoc>("pizzaMenu")
    const result2 = await pizzaMenuTB2.insertMany(docs)
    console.log("执行结果2------------------")
    console.log(JSON.stringify(result2))

}


run()
    .catch(error => {
        console.log(error)
    })
    .finally(() => {
        mongo.close()
        console.log("执行成功")
    })

